package com.example.login_demo.base;

import com.example.login_demo.ResourceTable;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.aafwk.content.Operation;
import ohos.app.Context;

public abstract class BaseAbilitySlice extends AbilitySlice {

    public Context mContext;
    public Ability mAbility;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        this.mContext=this.getContext();
        this.mAbility=this.getAbility();
        super.setUIContent(getLayout()); // 加载 XML 布局
        initView();
        initListener();


    }

    public abstract int getLayout();


    public abstract void initView();

    public abstract void initListener();

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }


    public void openAbility(IntentParams parameters,Class openClass,String action){

        Intent mIntent=new Intent();
        if(parameters!=null)
        {
            mIntent.setParams(parameters);
        }

        String mBundleName=openClass.getPackage().getName ();
        String mAbilityName=openClass.getName();

        Operation operatio= new Intent.OperationBuilder().withDeviceId("")
                .withBundleName(mBundleName)
                .withAbilityName(mAbilityName)
                .withAction(action)
                .build();
        mIntent.setOperation(operatio);
        startAbility(mIntent);

    }


}
